import Vue from 'vue'

import Cookies from 'js-cookie'

import Element from 'element-ui'
import  SksPluginElErp from 'sks-plugin-el-erp'
import './assets/styles/element-variables.scss'

import '@/assets/styles/index.scss' // global css
import '@/assets/styles/ruoyi.scss' // ruoyi css
import App from './App'
import store from './store'
import router from './router'
import directive from './directive' // directive
import plugins from './plugins' // plugins
import { download,downloadPost } from '/src/utils/request'

import './assets/icons' // icon
import './permission' // permission control
import { getDicts } from "/src/api/system/dict/data";
import { getConfigKey } from "/src/api/system/config";
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "/src/utils/ruoyi";
// 分页组件
import Pagination from "/src/components/Pagination";
// 自定义表格工具组件
import RightToolbar from "/src/components/RightToolbar"
// 富文本组件
import Editor from "/src/components/Editor"
// 文件上传组件
import FileUpload from "/src/components/FileUpload"
// 图片上传组件
import ImageUpload from "/src/components/ImageUpload"
// 图片预览组件
import ImagePreview from "/src/components/ImagePreview"
// 字典标签组件
import DictTag from '/src/components/DictTag'
// 头部标签组件
import VueMeta from 'vue-meta'
// 字典数据组件
import DictData from '/src/components/DictData'
import request from "./utils/request";

// 全局方法挂载
Vue.prototype.getDicts = getDicts
Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.download = download
Vue.prototype.downloadPost = downloadPost

Vue.prototype.handleTree = handleTree

// 全局组件挂载
Vue.component('DictTag', DictTag)
Vue.component('Pagination', Pagination)
Vue.component('RightToolbar', RightToolbar)
Vue.component('Editor', Editor)
Vue.component('FileUpload', FileUpload)
Vue.component('ImageUpload', ImageUpload)
Vue.component('ImagePreview', ImagePreview)

Vue.use(directive)
Vue.use(plugins)
Vue.use(VueMeta)
DictData.install()

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

Vue.use(SksPluginElErp,{
    request: request,
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})

//默认的存在精度问题 https://www.jianshu.com/p/849b0ae36b36
// 1.35.toFixed(1) // 1.4 正确
// 1.335.toFixed(2) // 1.33  错误
// 1.3335.toFixed(3) // 1.333 错误
// 1.33335.toFixed(4) // 1.3334 正确
// 1.333335.toFixed(5)  // 1.33333 错误
// 1.3333335.toFixed(6) // 1.333333 错误
Number.prototype.toFixed=function (d) {
    var s=this+"";
    if(!d)d=0;
    if(s.indexOf(".")==-1)s+=".";
    s+=new Array(d+1).join("0");
    if(new RegExp("^(-|\\+)?(\\d+(\\.\\d{0,"+(d+1)+"})?)\\d*$").test(s)){
        var s="0"+RegExp.$2,pm=RegExp.$1,a=RegExp.$3.length,b=true;
        if(a==d+2){
            a=s.match(/\d/g);
            if(parseInt(a[a.length-1])>4){
                for(var i=a.length-2;i>=0;i--){
                    a[i]=parseInt(a[i])+1;
                    if(a[i]==10){
                        a[i]=0;
                        b=i!=1;
                    }else break;
                }
            }
            s=a.join("").replace(new RegExp("(\\d+)(\\d{"+d+"})\\d$"),"$1.$2");

        }if(b)s=s.substr(1);
        return (pm+s).replace(/\.$/,"");
    }return this+"";

};

import * as ssc from './super-saiyan-constant.js'
import {checkPermi, checkRole} from "./utils/permission";
Vue.prototype.ssc = ssc
Vue.prototype.checkRole = checkRole
Vue.prototype.checkPermi =checkPermi
